/*
 * heat_internal.h
 *
 * heat module internal use.
 *
 * Author: lixiang<lixiang@sinhmicro.com.cn>
 * 
 * Encoding format: GB2312
 * Version: v1.2.2
 * Date: 2024-11-05
 */

#include <ss805x.h>	
#include "heat_config.h"

#if (CONFIG_HEATING_FREQUENCY < 300)
    #define HEAT_TIMER_COUNTER_VAL          (ROUND_DIV(1500000ul, CONFIG_HEATING_FREQUENCY))
    #define PWM_TRIG0_DEBOUNCE              (2000)
    #define PWM_TRIG1_DEBOUNCE              (435)
    #define PWM_GET_RES_DEBOUNCE            (600)
    #define PWM_CMPEN_DEBOUNCE              (10)
    #define PWM_CMPDIS_DEBOUNCE             (10)
#else
    #define HEAT_TIMER_COUNTER_VAL          (ROUND_DIV(12000000ul, CONFIG_HEATING_FREQUENCY))
    #define PWM_TRIG0_DEBOUNCE              (6400)
    #define PWM_TRIG1_DEBOUNCE              (1120)
    #define PWM_GET_RES_DEBOUNCE            (1800)

    #define PWM_CMPEN_DEBOUNCE              (80)
    #define PWM_CMPDIS_DEBOUNCE             (80)
#endif

#define HEAT_TIMER_RELOAD               (65535 - HEAT_TIMER_COUNTER_VAL)

#if (CONFIG_RES_MEASURE == 0)
    #define PWM_MAX_VALID_DUTY                  (HEAT_TIMER_COUNTER_VAL)
#else
    #if (CONFIG_RES_MEASURE_TIME == 1)
        #define PWM_MAX_VALID_DUTY              (HEAT_TIMER_COUNTER_VAL - PWM_GET_RES_DEBOUNCE)
    #else
        #define PWM_MAX_VALID_DUTY              (HEAT_TIMER_COUNTER_VAL)
    #endif
#endif
